package cn.cvs.service.sysRole;

import cn.cvs.dao.SysRoleMapper;
import cn.cvs.pojo.SysRole;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysRoleServiceImpl implements SysRoleService{

    @Resource
    private SysRoleMapper sysRoleMapper;

    /**
     * 查询所有用户信息
     *
     * @return
     * @throws Exception
     */
    @Override
    public List<SysRole> findAllSysRole() throws Exception {
        List<SysRole> list = sysRoleMapper.queryAllRoleList();
        return list;
    }

    /**
     * 添加角色
     *
     * @param sysRole
     * @return
     * @throws Exception
     */
    @Override
    public boolean addSysRole(SysRole sysRole) throws Exception {
        Integer row = sysRoleMapper.addSysRole(sysRole);
        if (row>0){
            return true;
        }else {
            return false;
        }
    }

    /**
     * 通过角色编码查询
     *
     * @param code
     * @return
     * @throws Exception
     */
    @Override
    public SysRole findSysRoleBycode(String code) throws Exception {
        return sysRoleMapper.querySysRoleByCode(code);
    }

    /**
     * 通过ID查询角色
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public SysRole findSysRoleById(String id) throws Exception {
        return sysRoleMapper.querySysRoleById(id);
    }

    /**
     * 修改角色
     *
     * @param sysRole
     * @return
     * @throws Exception
     */
    @Override
    public boolean updateSysRole(SysRole sysRole) throws Exception {
        Integer row = sysRoleMapper.modifySysRole(sysRole);
        if (row>0){
            return true;
        }else {
            return false;
        }
    }

    /**
     * 删除用户
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public boolean delete(String id) throws Exception {
        Integer row = sysRoleMapper.deleteSysRole(id);
        if (row>0){
            return true;
        }else {
            return false;
        }
    }

}
